/*
** Audio stream helper 
** We occasionally need to resample stuff (pretty much all the time), so why not have it go through here?
*/

#define BUFFER_MAX_SAMPLES 900000 //44100//22050


// TODO: Clean up this class! It sucks the anus
class CAudioBuffer {
	private:
		int   sr_native;
		int   sr_output;

		int channels;

		UINT8 left_volume;
		UINT8 right_volume;

		// TODO: change buffers so that they don't just go to a certain speaker.
		short* buf_l;		// buffer pointer (left speaker)
		short* buf_r;		// buffer pointer (right speaker)
		short* curptr_l;	// see above
		short* curptr_r;
		short* tempbuf;	   // Temp buffer for applying certain things (resampling, echo, etc)
		int    bufsize; 
		long  timestamp;   // timestamp in samples (in output sample rate)
		double realtime;   // how much time we've output for

	public:
		CAudioBuffer(int sr_native, int sr_output);
		~CAudioBuffer();

		long GetTimestamp() { return this->timestamp; } 
		
		void ApplyVolumeMix();
		int GetSampleRate() { return this->sr_native; }

		void ResetSamplePointers();
		short* GetLeftStream();
		short* GetRightStream();
		void DoneSamples(int count);
		void OnSampleComplete();   // Advance the timestamp
		void Resample();		   // Resample the buffer
		void Reset();

		
};
